let express = require('express');
let router = express.Router();
/* GET home page. */


/**
 * 用户注册
 */
router.all('/addUser', function (req, res, next) {
    global['bean'].UserService.addUserEntity(req.args).then(data => {
        res.json(res.wrap(20000, '添加用户成功!', data));
    }).catch(e => {
        next(e);
    });
});
/**
 * 删除用户
 */
router.all('/removeUser', function (req, res, next) {
    global['bean'].UserService.removeUserEntity(req.args).then(data => {
        res.json(res.wrap(20000, '删除用户成功!', data))
    }).catch(e => {
        next(e);
    });
});


/**
 * 更新用户
 */
router.all('/updateUser', function (req, res, next) {
    global['bean'].UserService.updateUserEntity(req.args).then(data => {
        res.json(res.wrap(20000, '修改用户成功!', data))
    }).catch(e => {
        next(e);
    });
});

/**
 * 删除用户
 */
router.all('/listUsers', function (req, res, next) {

    global['bean'].UserService.listUserEntities(req.args.start || 0, req.args.size || 10,req.args.keyWord).then(data => {
        res.json(res.wrap(20000, '查询用户', data))
    }).catch(e=>{
        next(e)
    })
});

module.exports = router;
